package com.example.mypicproject.adapter;

import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mypicproject.R;
import com.example.tanloadpic.BitmapHunter;

import java.util.ArrayList;
import java.util.List;

public class PicMainAdapter extends RecyclerView.Adapter<PicMainAdapter.ViewHolder> {



    List<Bitmap> list = new ArrayList<>();

    public PicMainAdapter(List<Bitmap> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_pic_main, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull  PicMainAdapter.ViewHolder holder, int position) {
        Bitmap bitmap = null;
        if (position<list.size()){
             bitmap = list.get(position);
        }

        holder.ivPicMain.setImageBitmap(bitmap);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView ivPicMain ;
        public ViewHolder(View view){
            super(view);
            ivPicMain = view.findViewById(R.id.iv_pic_main);
        }
    }


}
